//Everything in this file was created by Travis Lamb A.2

#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include "Order.h"

using namespace std;

//simple constructor
Order::Order(int odr, int svr, int tbl, int yer, int mth, int dte, int hr, int min)
{
	Order::order_id = odr;
	Order::server_id = svr;
	Order::table_id = tbl;
	//order_date.set_date(yer,mth,dte);
	Order::order_date = Date(yer,mth,dte);
	Order::order_time = Time(hr,min);
}

//instead of returning a string, display() simply displays the information itself
//perhaps later I will write a to_string() function that will return a string
void Order::display()
{
	cout << "\nOrder ID:\t" << order_id;
	cout << "\nServer ID:\t" << server_id;
	cout << "\nTable ID:\t"<<table_id;
	cout << "\nOrder Date:\t"<<order_date.to_string_date();
	cout << "\nOrder Time:\t"<<order_time.to_string_time() << endl;
}

//this function reads the first part of the orders.dat file and saves them onto a vector of Orders
void read_orders(vector<Order>& order_list, string filepath)
{
	//char *filepath =
	ifstream inFile;
	inFile.open((char*)filepath.c_str());
	if(inFile.fail())
	{
		cerr << "\n\nERROR: Unable to open file orders.dat\n\n";	//simple error checking
		return;
	}

	int end;	//the initial int is the number of lines to read
	inFile >> end;
	for(int x = 0;x < end;x++)
	{
		int odr, svr, tbl, yer, mth, dte, hr, min;
		inFile >> odr >> svr >> tbl >> yer >> mth >> dte >> hr >> min;	//input each int into the matching data type
		//Order(odr, svr, tbl, yer, mth, dte, hr, min).display();
		order_list.push_back(Order(odr, svr, tbl, yer, mth, dte, hr, min));	//add new Order to the vector
	}
}
